﻿using System;
using System.Collections.Generic;
using SimpleFS.Core;
using SimpleFS.Core.Implementations;

namespace SimpleFS.Services.Compression
{
    public class File : AbstractFile
    {
        internal IFile internalObject;

        internal ICompressionServiceProvider provider;

        public File(IFile internalObject, ICompressionServiceProvider provider) : base(internalObject)
        {
            this.provider = provider;
        }

        #region IFile Members

        public override System.IO.Stream Read()
        {
            return this.provider.Decompress(this.internalObject.Read());
        }

        public override void Write(System.IO.Stream stream)
        {
            this.internalObject.Write(this.provider.Compress(stream));
        }

        #endregion

        #region IFileSystemObject Members

        public override IDirectory ParentDirectory
        {
            get
            {
                return
                    new Directory(this.internalObject.ParentDirectory, this.provider);
            }
        }

        #endregion
    }
}
